package com.knowledge.controller;

import com.knowledge.vo.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.UUID;

/**
 * @author zzz
 * @create 2022-02-12 17:53
 */
@RestController
@RequestMapping("/upload")
public class UploadController {
//    @Autowired
//    private QiNiuUtil qiNiuUtil;

    @PostMapping
    public Result upload(@RequestParam("image")MultipartFile file) {
        //原始文件名称 比如aa.png
        String originalFileName = file.getOriginalFilename();
        //随机生成的uuid 唯一
        String filename = UUID.randomUUID().toString() + "." + StringUtils.substringAfterLast(originalFileName, ".");
        //上传文件
//        boolean upload = qiNiuUtil.upload(file, filename);
//        if(upload){
//            return Result.success(QiNiuUtil.url+filename);
//        }
        return Result.fail(20001,"上传失败");
    }
}
